Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use async processing to avoid database timeouts #437

Merged
merged 3 commits into from
Oct 9, 2023
Merged

Conversation

blootsvoets
Copy link
Member

@blootsvoets blootsvoets commented Sep 7, 2023

In the previous handling of events, event were handled immediately during the transaction, in the same thread. This caused a lot of delays, blocking the database threads. The EventListener annotations are replaced by TransactionalEventListener annotations to ensure that the previous transaction has been committed before processing the event. It explicitly creates a new transaction to avoid overlapping transactions. Finally, the Async annotation enables async processing to avoid the existing transaction threads being blocked.

This fixes an issue that caused timeouts if the fcm handling had timeouts.

@@ -55,7 +59,9 @@ public MessageStateEventListener(ObjectMapper objectMapper,
*
* @param event the event to respond to
*/
@EventListener(value = NotificationStateEventDto.class)
@Transactional(propagation = Propagation.REQUIRES_NEW)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have had transaction lock issues with postgres (aws rds) when using Propagation.REQUIRES_NEW previously, @mpgxvii can you elaborate the issues we faced previously.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, using TransactionalEventListener + Async was essential, because it only opens a new transaction once the old one is committed. In earlier tests with other permutations, the transactions would overlap and block the HikariCP thread pool.

Copy link
Member

@mpgxvii mpgxvii Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I see, sounds good. Yes we had to remove the REQUIRES_NEW propagation previously because it was resulting in "Too many connections" issue which was blocking other transactions and causing inconsistent states.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpgxvii perhaps we can test this with our stage cluster?

In the previous handling of events, event were handled
immediately during the transaction, in the same thread. This caused a
lot of delays, blocking the database threads. The EventListener annotations are replaced by
TransactionalEventListener to ensure that the previous transaction has
been committed before processing the event. It explicitly creates
a new transaction to avoid overlapping transactions. Finally, it enables
async processing to avoid the existing transaction threads being blocked.
Copy link
Member

@mpgxvii mpgxvii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mpgxvii mpgxvii merged commit b4ebd3e into dev Oct 9, 2023
6 checks passed
@blootsvoets blootsvoets deleted the limitTransactionTime branch October 9, 2023 11:31
@mpgxvii mpgxvii mentioned this pull request Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants